PHP: Smarty: {foreach} doesn't render my array
Working with arrays in Smarty templates
On one of the websites I work with I couldn't render an array in a smarty template. My code looked like this:{foreach from=$myarray key=mykey item=items}
<h2>{$mykey}</h2>
{foreach from=$items item=it}
{$it.value}
{/foreach}
{/foreach}
I used print_r in my controller to show content of $myarray and it was just fine. After a while I found the error: Zend Framework did not allow me
to work directly on an array which is to be passed to Smarty.
So instead of:
$this->view->myarray = array();
foreach ($array AS $ar)
{
$this->view->myarray[$ar['name']] = $ar;
}
I had to use:$temp = array();
foreach ($array AS $ar)
{
$temp[$ar['name']] = $ar;
}
$this->view->myarray = $temp;
Kinda weird behavior, but...
Comments